/**
 * GridPanelMediator.as
 * Copyright 2014 Qunhe Tech, all rights reserved.
 * Qunhe PROPRIETARY/CONFIDENTIAL, any form of usage is subject to approval.
 */
package org.bridge.flash.hi2048.view
{
    import flash.events.Event;

    import org.bridge.flash.hi2048.model.GameModel;
    import org.bridge.flash.hi2048.model.constants.OperationType;
    import org.bridge.flash.hi2048.view.event.OperationEvent;

    import robotlegs.bender.bundles.mvcs.Mediator;

    /**
     * @author zhangshuai
     */
    public class GridPanelMediator extends Mediator
    {
        [Inject]
        public var gridPanel:GridPanel;

        [Inject]
        public var gameModel:GameModel;

        public function GridPanelMediator()
        {
        }

        override public function initialize():void
        {
            gridPanel.initMatrix(gameModel.matrix);
            gridPanel.addEventListener(OperationEvent.OPERATE, onOperate);
        }

        protected function onOperate(event:OperationEvent):void
        {
            if (OperationType.isOperationType(event.keyCode))
            {
                gameModel.matrix.operate(event.keyCode);
            }
        }

    }
}
